home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / migration-assistant / ma-script-utils
Encoding:
Text File  |  2007-04-05  |  4.6 KB  |  184 lines

  1. #!/bin/sh
  2.  
  3. . /usr/share/debconf/confmodule
  4.  
  5. error () {
  6.     logger -t migration-assistant "error: $@"
  7. }
  8.  
  9. log () {
  10.     logger -t migration-assistant "info: $@"
  11. }
  12.  
  13. ostype=""
  14. set_os_type () {
  15. # Rather than test for every distro possible in the shortname, we test
  16. # the bootloader type for 'linux.'  This *should* be fine as we're only
  17. # working with user's home directories.
  18.  
  19.     if [ ${1##*:} = "linux" ]; then
  20.     ostype="linux"
  21.     return 0
  22.     fi
  23.     
  24.     case `expr match "$1" '.*:.*:\(.*\):.*'` in
  25.     "Windows" )
  26.     ostype="windowsxp"
  27.         return 0
  28.     ;;
  29.  
  30.     "Windows9xMe" )
  31.     ostype="windows9x"
  32.         return 0
  33.     ;;
  34.  
  35.     "MacOSX" )
  36.     ostype="macosx"
  37.         return 0
  38.     ;;
  39.  
  40.     *)
  41.     echo "Unknown ostype from $1" 1>&2
  42.     return 1
  43.     ;;
  44.     esac
  45. }
  46. mountpoint="/mnt/migrationassistant"
  47.  
  48. unmount_os() {
  49.     device="$1"
  50.  
  51.     if [ -f /etc/mtab ]; then
  52.         MTAB=/etc/mtab
  53.     else
  54.         MTAB=/proc/mounts
  55.     fi
  56.  
  57.     while :; do
  58.         failed=
  59.         
  60.     ISMOUNTED=
  61.     if [ "$device" ]; then
  62.         ISMOUNTED=$(grep "^$device " $MTAB) || ISMOUNTED=
  63.     else
  64.         ISMOUNTED=$(grep " $mountpoint " $MTAB) || ISMOUNTED=
  65.     fi
  66.         if [ -z "$ISMOUNTED" ]; then
  67.             break
  68.         fi
  69.         HOME=$(grep " $mountpoint/home " $MTAB) || HOME=
  70.         if [ "$HOME" ]; then
  71.             umount "$mountpoint/home" || failed="$mountpoint/home"
  72.         fi
  73.         if [ -z "$failed" ]; then
  74.             if [ -z "$device" ]; then
  75.                 umount $mountpoint || failed="$mountpoint"
  76.             else
  77.                 umount $device || failed="$device"
  78.             fi
  79.         fi
  80.  
  81.         if [ -z "$failed" ]; then
  82.             break
  83.         fi
  84.         db_reset migration-assistant/failed-unmount
  85.         db_subst migration-assistant/failed-unmount MOUNTED "$failed"
  86.         db_input critical migration-assistant/failed-unmount || true
  87.         db_go || exit 10
  88.         db_get migration-assistant/failed-unmount
  89.         [ "$RET" = true ] || exit 10
  90.     done
  91. }
  92.  
  93. mount_os () {
  94.     ostype="$1"
  95.     device="$2"
  96.  
  97.     mkdir -p $mountpoint
  98.     unmount_os $device
  99.  
  100.     if [ "$1" = "linux" ]; then
  101.     mount $device $mountpoint
  102.     if [ -f "$mountpoint/etc/fstab" ]; then
  103.             while read uuid mp rest; do
  104.             if [ "$mp" != "/home" ]; then
  105.             continue
  106.         fi
  107.  
  108.         if [ "${uuid%=*}" = "UUID" ]; then
  109.                     devname="/dev/disk/by-uuid/${uuid#*=}"
  110.             uuid=$(readlink -e "$devname") || \
  111.                         error "$devname does not exist."
  112.         elif [ "${uuid%=*}" = "LABEL" ]; then
  113.             devname="/dev/disk/by-label/${uuid#*=}"
  114.                     uuid=$(readlink -e "$devname") || \
  115.                         error "$devname does not exist."
  116.                 elif [ ! -e "$uuid" ]; then
  117.                     # This happens when the IDE driver in the old OS doesn't
  118.                     # match the driver in the installer.  The old /home might be
  119.                     # mounted on /dev/hda3 which could now be /dev/sda3 or
  120.                     # something entirely different.  Since there's no way to
  121.                     # determine what the device is without the old kernel
  122.                     # loaded, we fail gracefully so that we can continue to the
  123.                     # next OS.
  124.                     log "$uuid does not exist, continuing."
  125.                     break
  126.                 fi
  127.                 failed=
  128.         mount $uuid "$mountpoint/home" || failed="1"
  129.                 if [ "$failed" ]; then
  130.             unmount_os "$uuid"
  131.             mount $uuid "$mountpoint/home" || \
  132.                         error "failed to mount $uuid"
  133.         fi
  134.         break
  135.             done < "$mountpoint/etc/fstab"
  136.         fi
  137.     elif [ "$1" = "windowsxp" ]; then
  138.     mount -t ntfs $device $mountpoint -o umask=0022,nls=utf8 || \
  139.     ( log "Mounting $device to $mountpoint with NTFS failed."
  140.     mount -t vfat $device $mountpoint -o umask=0022,utf8 || \
  141.     log "Mounting $device to $mountpoint with VFAT failed." )
  142.     fi
  143.  
  144. }
  145.  
  146. ROOT=/target
  147. add_user() {
  148.     local username
  149.     local fullname
  150.     local password
  151.  
  152.     username="$1"
  153.     fullname="$2"
  154.     password="$3"
  155.  
  156.     chroot=chroot
  157.     log='log-output -t migration-assistant'
  158.  
  159. # Taken from user-setup/user-setup-apply
  160.  
  161.     # Add the user
  162.     if [ -x $ROOT/usr/sbin/adduser ]; then
  163.         $chroot $ROOT adduser --disabled-password --gecos \
  164.         "$fullname" "$username" >/dev/null || true
  165.     else
  166.         $chroot $ROOT useradd -c "$fullname" -m "$username" >/dev/null || true
  167.     fi
  168.  
  169.     # Set the password
  170.     $chroot $ROOT chpasswd -m <<EOF
  171. $username:$password
  172. EOF
  173.  
  174.     # Add the user to groups
  175.     if [ -n "$username" ]; then
  176.         for group in adm audio cdrom dialout floppy video plugdev dip lpadmin scanner; do
  177.             #$log 
  178.             $chroot $ROOT adduser "$username" $group >/dev/null 2>&1 || true
  179.         done
  180.  
  181.     fi
  182. }
  183. # vim:ai:et:sts=4:tw=80:sw=4:
  184.